#pragma once

#include "Material/Material.h"
#include "Mesh/StaticMesh.h"
#include "Misc/StdHead.h"
#include "Scene/SceneNodeComponent.h"
#include "StaticMeshComponent.m.h"

class CPhysicalBody;
class CRenderMeshInstance;

RCLASS() 
class WHENGINE_API RStaticMeshComponent:public RSceneNodeComponent
{
    ROBJECT
public:


    RFUNCTION()
    void SetStaticMesh(TSharedObjectPtr<RStaticMesh> InMesh);

    RFUNCTION()
    TSharedObjectPtr<RStaticMesh> GetStaticMesh()
    {
        return Mesh;
    }

    RFUNCTION()
    void SetMaterials(TVector<TSharedObjectPtr<RMaterial>> InMaterials);

    RFUNCTION()
    void SetMaterial(TSharedObjectPtr<RMaterial> InMaterial,int32_t InSectionIndex=0);


    void EnablePhysics(bool InEnable);

    bool IsPhysicsEnabled();

    bool ShouldRender()
    {
        return !Hidden;
    }

    RFUNCTION()
    bool GetHidden()
    {
        return Hidden;
    }
    
    RFUNCTION()
    void SetHidden(bool InNewHidden)
    {
        Hidden=InNewHidden; 
    }


    RFUNCTION()
    void SetCastShadow(bool InCastShadow)
    {
        bCastShadow=InCastShadow;
    }

    RFUNCTION()
    bool CanCastShadow()
    {
        return bCastShadow;
    }
private:
    RFIELD(NotInScript)
    TSharedObjectPtr<RStaticMesh> Mesh;

    RFIELD(NotInScript)
    TVector<TSharedObjectPtr<RMaterial>> Materials;

    RFIELD(NotInScript)
    bool Hidden=false;

    RFIELD(NotInScript)
    bool bCastShadow=true;

public:
    virtual void Paint(CRenderScene* InRenderData) override;

    SMatrix4x4 GetWorldTransform();

protected:
};